
/*
 * Hlpay-Plus aggregate payment system.
 * Copyright (c) 2024-2025 Hlpay Team Copyright has the right of final interpretation.
 */

package com.hlkj.pay.config;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.boot.context.properties.ConfigurationProperties;

import lombok.Data;

/**
 * Description: 租户拦截器配置信息
 * <br/>
 * InterceptorProperties
 *
 * @author laiql
 * @date 2024/09/17 17:11
 */
@Data
@ConfigurationProperties(prefix = InterceptorProperties.ADMIN_PREFIX)
public class InterceptorProperties {
    public final static String ADMIN_PREFIX = "admin.hlkj.interceptor";

    /**
     * 默认忽略
     */
    private static final String[] IGNORE_ENDPOINTS = {
            "/health",
            "/error",
            "/v3/api-docs/**",
            "/swagger-ui/**",
            "/doc.**",
            "/actuator/**",
            "/webjars/**"
    };

    /**
     * 默认拦截
     */
    private static final String[] URL_ENDPOINTS = {"/**"};
    /**
     * 忽略租户拦截URL
     */
    private List<String> ignoreTokenUrl = new ArrayList<>();
    /**
     * open api 开头的url
     */
    private List<String> ignoreClientApiTokenUrl = new ArrayList<>();
    /**
     * client api 开头的url
     */
    private List<String> clientApiTokenUrl = new ArrayList<>();
    /**
     * callback api 开头的url
     */
    private List<String> callBackApiTokenUrl = new ArrayList<>();
    /**
     * 忽略权限拦截URL
     */
    private List<String> ignorePermissionUrl = new ArrayList<>();

    /**
     * 配置拦截url，默认: /**
     */
    private List<String> urls = new ArrayList<>();
    /**
     * 配置拦截url，默认: /**
     * 默认租户拦截
     */
    private List<String> defaultTenantUrls = new ArrayList<>();

    /**
     * 首次加载合并ENDPOINTS
     */
    @PostConstruct
    public void initUrl() {
        Collections.addAll(urls, URL_ENDPOINTS);
        Collections.addAll(ignoreTokenUrl, IGNORE_ENDPOINTS);
        ignoreTokenUrl.add("/openapi/**");
        ignorePermissionUrl.addAll(ignoreTokenUrl);
    }
}